﻿using System.ServiceModel.DomainServices.Client;
using System.Windows;
using System.Windows.Controls;
using GSSoftSL.ViewModel.HocVienVM;
using GSSoftSL.Web;
using GSSoftSL.Web.Models;

namespace GSSoftSL.Views.HocVienView
{
    /// <summary>
    /// Description for HocVienEditView.
    /// </summary>
    public partial class HocVienEditView : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the HocVienEditView class.
        /// </summary>
        public HocVienEditView()
        {
            InitializeComponent();
        }

        /*private void dataForm_ContentLoaded(object sender, DataFormContentLoadEventArgs e)
        {
            HocVien hv = dataForm.CurrentItem as HocVien;
            if (hv != null && hv.EntityState == EntityState.Detached)
            {
                dataForm.BeginEdit();
                ((HocVienEditViewModel) this.dataForm.DataContext).Mode = DataFormMode.AddNew;
            }
        }

        private void dataForm_EditEnded(object sender, DataFormEditEndedEventArgs e)
        {
            if (e.EditAction == DataFormEditAction.Commit)
            {
                //dataForm.CommitEdit();
                ((HocVienEditViewModel) this.dataForm.DataContext).SaveCommand.Execute(true);
            }
            else
            {
                if (((HocVienEditViewModel)this.dataForm.DataContext).HocVien.EntityState == EntityState.Detached)
                    ((HocVienEditViewModel)this.dataForm.DataContext).HocVien = null;
                dataForm.CancelEdit();
            }
            ((HocVienEditViewModel)this.dataForm.DataContext).Mode = DataFormMode.ReadOnly;
        }

        private void dataForm_BeginningEdit(object sender, System.ComponentModel.CancelEventArgs e)
        {
            ((HocVienEditViewModel)this.dataForm.DataContext).Mode = DataFormMode.Edit;
        }*/

        public void SetStatus(bool Enabled)
        {
            this.IsEnabled = Enabled;
        }

        private void btnCancel_Click(object sender, System.Windows.RoutedEventArgs e)
        {
        	SetStatus(false);
        }
    }
}